﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using l1cs.server.model.Instance;
using l1cs.server.model;
using l1cs.server.datatables;
using l1cs.server.templates;

namespace l1cs.server.clientpackets
{
    public class C_Deposit : ClientBasePacket
    {
        private const String _C_DEPOSIT = "[C] C_Deposit";
        private static Logger _log = Logger.getLogger( typeof( C_Deposit ).FullName );

        public C_Deposit( byte[] abyte0, ClientThread clientthread )
            : base( abyte0 )
        {
            int i = readD();
            int j = readD();

            L1PcInstance player = clientthread.getActiveChar();
            if ( i == player.getId() )
            {
                L1Clan clan = L1World.getInstance().getClan( player.getClanname() );
                if ( clan != null )
                {
                    int castle_id = clan.getCastleId();
                    if ( castle_id != 0 )
                    { // 城主クラン
                        L1Castle l1castle = CastleTable.getInstance()
                                .getCastleTable( castle_id );
                        lock ( l1castle )
                        {
                            int money = l1castle.getPublicMoney();
                            if ( player.getInventory()
                                    .consumeItem( L1ItemId.ADENA, j ) )
                            {
                                money += j;
                                l1castle.setPublicMoney( money );
                                CastleTable.getInstance().updateCastle( l1castle );
                            }
                        }
                    }
                }
            }
        }

        override
        public String getType()
        {
            return _C_DEPOSIT;
        }
    }
}